package android.registrazione;

import java.util.LinkedList;
import java.util.Properties;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;


public class registrazione extends Activity {

	private static final String SOAP_ACTION = "salvaUtente";
	private static final String METHOD_NAME = "salvaUtente";
	private static final String NAMESPACE = "urn:Registrazione";
	private static final String URL = "http://192.168.0.8:8080/axis/services/Registrazione?wsdl";

	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        invocaWebService();
 /*       setContentView(R.layout.main);
        
        Button button = (Button) findViewById(R.id.salva);
        final EditText edit = (EditText)findViewById(R.id.nome);
        
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            	invocaWebService();
            }
        });*/
    }
   
    
    public void invocaWebService(){
    	
    	LinkedList<String> ll = new LinkedList<String>();
    	ll.add("String 1");
    	ll.add("String 2");

    	try{
    		
    	SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    	request.addProperty("nome","antonino");
    	request.addProperty("cognome","antonino");    	
    	request.addProperty("via","antonino");
    	request.addProperty("username","antonino");       	
    	request.addProperty("password","antonino");
    	request.addProperty("sesso",new Boolean(true));
    	request.addProperty("interessi",ll);    	
    	
    	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    	envelope.setOutputSoapObject(request);
    	
    	AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
    	
    	androidHttpTransport.call(SOAP_ACTION, envelope);
    	
    	
    	
    	
    	
    	Object resultsRequestSOAP = envelope.getResponse();
    	
    	String[] results = (String[])  resultsRequestSOAP;


    	TextView tv = new TextView(this);
    	
    	tv.setText( results[0]);
    
    	setContentView(tv);
    	

    	

    	
    	}
    	catch(Exception e)
    	{
    		TextView tv = new TextView(this);
    		tv.setText(e.toString());
    		setContentView(tv);
    		
    		Log.i("Error",e.getMessage());
    	}
    }
    
    
    
    
    
}